package org.swust.sysmonitorapp.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.GetMapping;
import org.swust.sysmonitorapp.dto.SysUserDto;
import org.swust.sysmonitorapp.entity.CountDepartment;
import org.swust.sysmonitorapp.entity.QSysUser;
import org.swust.sysmonitorapp.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * 用户表 Mapper 接口
 *
 * @since 2024-12-24
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {
    IPage<SysUserDto> pageUser(Page<SysUserDto> page, @Param("param") QSysUser qSysUser);

    @Update("update sys_user set password = #{password} where user_id = #{id}")
    int updatePassword(@Param("id") Integer id, @Param("password") String password);

    //@Select("SELECT d.dept_name AS departmentName, COUNT(*) AS userCount FROM sys_user u JOIN sys_department d ON u.dept_id = d.dept_id GROUP BY d.dept_id")
    List<CountDepartment>countDepartment();

    @Update("update sys_user set password = #{password} where user_id = #{id}")
    int resetPwd(@Param("id") Integer id, @Param("password") String password);
}
